<template>
	<view class="page">
		<u--form labelPosition="left" :model="model" ref="form1">

			<u-form-item label="联系姓名" label-width="80" prop="userInfo.userName" borderBottom ref="item1">
				<u--input v-model="model.userInfo.userName" placeholder="请输入联系人姓名" border="none"></u--input>
			</u-form-item>
			<u-form-item label="联系电话" label-width="80" prop="userInfo.userPhone" borderBottom ref="item1">
				<u--input v-model="model.userInfo.userPhone" placeholder="请输入联系人电话" border="none"></u--input>
			</u-form-item>

			<u-form-item label="性别" label-width="80" prop="sex" borderBottom @click="sexshow = true; hideKeyboard()"
				ref="item1">
				<u--input v-model="sex" disabled disabledColor="#ffffff" placeholder="请选择性别" border="none"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>

			<u-form-item label="学历" label-width="80" borderBottom @click="xuelishow = true; hideKeyboard()" ref="item1">
				<u--input v-model="xueli" disabled disabledColor="#ffffff" placeholder="请选择学历" border="none"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="出生日期" label-width="80" borderBottom @click="startTimeShow(); hideKeyboard()"
				ref="item1">
				<u--input v-model="model.userInfo.userBirthDate" disabled disabledColor="#ffffff" placeholder="请选择日期" border="none"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
		</u--form>

		<view class="commitBg">
			<button class="btn" @click="submit">提交</button>
		</view>
		<!-- <u-picker v-model="riqishow" mode="date" @confirm="confirm"></u-picker> -->
		<!-- <u-picker v-model="show" mode="time" @confirm="confirm"></u-picker> -->
		<u-action-sheet :show="sexshow" :actions="sexList" title="请选择性别" @close="sexshow = false;genderClose()"
			@select="sexSelect()">
		</u-action-sheet>
		<u-action-sheet :show="xuelishow" :actions="xueliList" title="请选择学历" @close="xuelishow = false;"
			@select="xueliSelect()">
		</u-action-sheet>
		<u-datetime-picker ref="startPick" :show="startShow" :minDate="minDate" v-model="form.start_date"
			mode="date" @confirm="confirm" @cancel="startShow=false"></u-datetime-picker>

	</view>
</template>

<script>
	import Index from '@/common/index-model.js'
	let index = new Index();
	export default {
		data() {
			return {
				sex: '',
				xueli: '',
				riqi: '',
				sexshow: false,
				xuelishow: false,
				startShow: false,
				// minDate: new Date('1980-01-01').getTime(),
				
                riqi: new Date().toISOString().slice(0, 10),
				form: {
					start_date: '',
				},
				model: {
					userInfo: {
						orderId: '',
						userId: '',
						userName: '',
						userSex: 0,
						userEducationId: '',
						userBirthDate: new Date().toISOString().slice(0, 10),
						userPhone: '',
						inviteUserId:''
					}
				},
				sexList: [{
						name: '男',
					},
					{
						name: '女',
					}
				],
				xueliList: [],
				xueliData: []
			}
		},
		onLoad(option) {
			let inviteUserId =uni.getStorageSync('inviteUserId')
			
			this.model.userInfo.inviteUserId = inviteUserId
			// this.data = option.data
			console.log('传过来的值是==666666666666666==',option.data,uni.getStorageSync('userid'))
			this.sex = '男'
			this.getxueLiData()//uni.setStorageSync('userid', res.data.result.userId);
			this.model.userInfo.userId = uni.getStorageSync('userid')
			this.model.userInfo.orderId = option.data
		},
		methods: {
			submit() {
				if(this.model.userInfo.userName==''){
					uni.showToast({
						title:'请输入姓名',
						icon:"none"
					})
					return
				}
				if(this.model.userInfo.userPhone==''){
					uni.showToast({
						title:'请输入手机号',
						icon:"none"
					})
					return
				}
				console.log("提交信息:" + JSON.stringify(this.model.userInfo))
				index.getPublicUserMember(this.model.userInfo, 'orderUserRegister/register', 'post', res => {
					if (res.data.success && res.data.code == 200) {
						uni.showToast({
							title:'发布成功'
						})
						uni.navigateBack()
					} 
				})
			},
			 timestampToTime(timestamp) {
			  const date = new Date(timestamp)
			  const Y = date.getFullYear() + '-'
			  const M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
			  const D = (date.getDate() < 10 ? '0'+(date.getDate()) : date.getDate()) + ' '
			  const h = (date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':'
			  const m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':'
			  const s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds())
			  return Y+M+D+h+m+s
			},
			startTimeShow(){
						this.startShow = true
						// if(!this.form.start_date){
						// 	this.$refs.startPick.innerValue = new Date('2023-12-10').getTime()	
						// }
					},
			confirm(e) {
					this.startShow = false
					let time = this.timestampToTime(e.value)
					let arr = time.split(' ')
					this.model.userInfo.userBirthDate = arr[0]
					console.log('选择的时间是', this.model.userInfo.userBirthDate)
			},
			// 隐藏键盘
			hideKeyboard() {
				uni.hideKeyboard()
			},
			sexSelect(e) {
				this.model.userInfo.userSex = e.index
				console.log('选择的性别是', e)
				this.sex = e.name
			},
			xueliSelect(e) {
				// this.model.userInfo.userEducationId = e.index
				console.log('选择的工资单位是', e)
				this.xueli = e.name
				this.model.userInfo.userEducationId = this.xueliData[e.index].id
			},
			getxueLiData() {
				index.getPublicUserMember({}, 'client/public/educationList', 'get', res => {
					if (res.data.success && res.data.code == 200) {
						this.xueliData = res.data.result
						// this.gongzhongisShow=true
						this.xueli = this.xueliData[0].name
						this.model.userInfo.userEducationId = this.xueliData[0].id
						let arr = []
						for (let k = 0; k < this.xueliData.length; k++) {
							arr.push({
								"name": this.xueliData[k].name
							})
						}
						this.xueliList = arr
						console.log('学历', this.xueliList)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.page {
		margin: 15px;
		// background-color: gainsboro;
	}
	.commitBg{
		margin-top: 50px;
		border-radius: 8rpx;
		height: 45px;
		.btn{
			color: #fff;
			border-radius: 8rpx;
			background: #0575ff;
			font-size: 28rpx;
			height: 45px;
		}
	}
</style>